<?php

function NanoSavePrgm($u, $name, $prgm)
{
	$prgmlist = NanoOpenPrgmFile($u);
	$prgmlist[$name] = $prgm;
	return NanoSavePrgmFile($u, $prgmlist);
}

function NanoOpenPrgmFile($u)
{
	$file = './prgm/' . $u->id . '.prgm';
	if(file_exists($file))
	{
		$content = file_get_contents($file);
		$data = explode("::", $content);
		$names = explode(":", $data[0]);
		$prgms = explode(":", $data[1]);
		$prgmlist = array_combine($names, $prgms);
	}
	else
		$prgmlist = array();
	return $prgmlist;
}

function NanoSavePrgmFile($u, $prgmlist)
{
	$file = './prgm/' . $u->id . '.prgm';
	$names = array_keys($prgmlist);
	$prgms = array_values($prgmlist);
	$data = implode(":", $names) . '::' . implode(":", $prgms);
	return file_put_contents($file, $data);
}

?>